#ifndef DETECTORWINDOW_H
#define DETECTORWINDOW_H


#include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QVBoxLayout>
#include <QGridLayout>
#include "opencv2/opencv.hpp"
#include "object.h"
#include "blink.h"

#define UNIT_SIZE 23.6f // the calibration chessboard square size in Millimetres

class PreviewWindow;

/*
    This class is to run two eye detector threads
    and shows the debugging window
*/

class DetectorWindow : public QWidget
{
    Q_OBJECT
public:
    explicit DetectorWindow(QWidget *parent = 0);
    BlinkDetector * _detector0, * _detector1;
public slots:
    void updateEyeCam0( Point2f, Point2f );
    void updateEyeCam1( Point2f, Point2f );
private:
    CvCapture * capture0, * capture1;
    QGridLayout * _layout_main;
    PreviewWindow * _pv_0, * _pv_1;
    Mat cameraMatrix[2], distCoeffs[2], R[2], P[2], Q;
    Mat rmap[2][2];
    void loadCamParams();
    Mat pnts3d;
    Point2f leyes[2], reyes[2];
};


class PreviewWindow : public QWidget
{
    Q_OBJECT
public:
    PreviewWindow(QWidget *parent = 0);
    static QPixmap cvtCvImg2QtImg( IplImage * );
public slots:
    void displayCVImage( IplImage *, IplImage * = 0 );
    void updateEyeCam( Point2f, Point2f, Mat );
private:
    QLabel * _frame, * _km;
    static QImage dummy;
    const static int PV_W = 480, PV_H = 360;
    static QSize PV_SIZE;
};

#endif // DETECTORWINDOW_H
